package com.zzyl.controller.customer;

import com.zzyl.base.PageBean;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ReservationDto;
import com.zzyl.dto.ReservationQueryDto;
import com.zzyl.entity.Reservation;
import com.zzyl.service.ReservationService;
import com.zzyl.vo.ReservationVo;
import com.zzyl.vo.TimeCountVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/customer/reservation")
@Api(tags = "客户预约管理")
public class CustomerReservationController {
    private static final Logger log = LoggerFactory.getLogger(CustomerReservationController.class);
    @Autowired
    private ReservationService reservationService;

    @ApiOperation("查询取消预约数量")
    @GetMapping("cancelled-count")
    public ResponseResult<Integer> getCancelledCount() {
        log.info("查询取消预约数量");
        return ResponseResult.success(reservationService.getCancelledCount());
    }

    @ApiOperation("查询每个时间段剩余预约次数")
    @GetMapping("countByTime")
    public ResponseResult<List<TimeCountVo>> countByTime(Long time) {
        log.info("查询每个时间段剩余预约次数:{}", time);
        List<TimeCountVo> list = reservationService.countByTime(time);
        return ResponseResult.success(list);
    }


    @ApiOperation("新增预约")
    @PostMapping
    public ResponseResult<Void> add(@RequestBody ReservationDto dto) {
        log.info("新增预约: {}", dto);
        reservationService.add(dto);
        return ResponseResult.success();
    }


    @ApiOperation("分页查询预约")
    @GetMapping("page")
    public ResponseResult<PageBean<ReservationVo>> findByPage(ReservationQueryDto dto) {
        log.info("分页查询预约: {}", dto);
        PageBean<ReservationVo> reservationVoList = reservationService.findByPage(dto);
        return ResponseResult.success(reservationVoList);
    }


    @ApiOperation("取消预约")
    @PutMapping("{id}/cancel")
    public ResponseResult<Void> cancel(@PathVariable Long id) {
        log.info("取消预约: {}", id);
        reservationService.cancel(id);
        return ResponseResult.success();
    }
}
